#pragma once
#include"log.hpp"
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<boost/algorithm/string.hpp>
#include"jiebainclude/Jieba.hpp"
namespace ns_util//工具集
{
  class FileUtil
  {
  public:
    static bool ReadFile(const std::string &file_path,std::string *out)//从指定路径读取文件内容
    {
      std::ifstream in(file_path,std::ios::in);
      if(!in.is_open())
      {
        //std::cerr<<"open file"<<file_path<<" error"<<std::endl;
        LOG(FATAL,"文件打开失败！");
        return false;
      }

      std::string line;
      while(std::getline(in,line))//按行读取文件
      {
        *out+=line;
      }

      in.close();
      return true;
    }
  };
  
  class StringUtil
  {
  public:
   static void Split(const std::string& line ,std::vector<std::string> *results,const std::string& sep )
    {
      boost::split(*results,line,boost::is_any_of(sep),boost::token_compress_on);//对串入字符串按分隔符进行分开
    }
  };
  //用来分词的词库路径 
 const char* const DICT_PATH = "dict/jieba.dict.utf8";
 const char* const HMM_PATH = "dict/hmm_model.utf8";
 const char* const USER_DICT_PATH = "dict/user.dict.utf8";
 const char* const IDF_PATH = "dict/idf.utf8";
 const char* const STOP_WORD_PATH = "dict/stop_words.utf8";
 class JiebaUtil
 {
 private:
   static cppjieba::Jieba jieba;
 public:
   static void CutString(const std::string &src,std::vector<std::string> *out)
   {
     jieba.CutForSearch(src,*out);//对穿入的字符串进行分词并返回
   }
 };
 cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH);
}
